﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;
using System.Text;

namespace WebSite.cn
{
    public partial class category : System.Web.UI.UserControl
    {
        // Fields
        public StringBuilder strTypeMsgt = new StringBuilder();
        readonly BasePage theBasePage = new BasePage();

        private string sBigType
        {
            get
            {
                return Request.QueryString["sid"];
            }
        }

        // Methods
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                string sql = string.Empty;;
                string sType = string.Empty;;
                 if (sBigType == "2")
                {
                    sType = " and proisnew2 = 1";
                }
                
                else if(sBigType == "3")
                {
                    sType = " and proisnew3 = 1";
                }
                else if (sBigType == "4")
                {
                    sType = " and proisnew4 = 1";
                }
                 else
                     {
                         sType = " and (proisnew3 = 1 or proisnew4 =1) ";
                     }
                sql = "select distinct classid,classname,parentid,classorder from DB_Productclass where  visible=1 and parentid = 0  "
                    + " and classid in (select PC.parentid from DB_Productclass PC join DB_Shoppro S on PC.classid = S.typeid and S.proisshow = 1 and S.visible=1 and PC.parentid !=0 and PC.visible=1 " + sType +")"
                    + " and  parentid=0 and visible=1 order by classorder";
         
                DataTable table = SQLAccess.GreatDs(sql).Tables[0];
                if (table.Rows.Count > 0)
                {
                 
                    foreach (DataRow row in table.Rows)
                    {
                        strTypeMsgt.Append( "<h1><font>" + row["classname"].ToString() + "</font></h1>");
                        DataTable table2 = SQLAccess.GreatDs("select distinct PC.classid,PC.classname,PC.parentid,PC.classorder from DB_Productclass PC join DB_Shoppro S on PC.classid=S.typeid and S.proisshow = 1 and S.visible=1  " + sType + " where PC.parentid=" + row["classid"].ToString() + " and PC.visible=1 order by PC.classorder").Tables[0];
                        if (table2.Rows.Count > 0)
                        {                      
                            strTypeMsgt.Append(  "<table border='0' cellpadding='0' cellspacing='0'><tr>");
                            string sSelectCSS = string.Empty;
                            //int num = 0;
                            foreach (DataRow row2 in table2.Rows)
                            {
                                if (Request.QueryString["typeid"] == row2["classid"].ToString())
                                {
                                    sSelectCSS = "select";
                                }
                                else
                                {
                                    sSelectCSS = string.Empty;
                                }
               
                                if (Request.QueryString["sid"] == "2")
                                {
                                   strTypeMsgt.Append("<td class='" + sSelectCSS + "'  width='50%'><a href='professionArea.aspx?sid=" + Request.QueryString["sid"] + "&typeid=" + row2["classid"].ToString() + "'>" + row2["classname"].ToString() + "</a></td>");
                                }
                                else
                                {
                                    if(string.IsNullOrEmpty(Request.QueryString["sid"] ))
                                    {
                                        strTypeMsgt.Append("<td class='" + sSelectCSS + "' width='50%'><a href='hotpro.aspx?typeid=" + row2["classid"].ToString() + "'>" + row2["classname"].ToString() + "</a></td>");
                                    }else
                                    {
                                        strTypeMsgt.Append("<td class='" + sSelectCSS + "' width='50%'><a href='hotpro.aspx?sid=" + Request.QueryString["sid"] + "&typeid=" + row2["classid"].ToString() + "'>" + row2["classname"].ToString() + "</a></td>");
                                    }
                                }
                               
                                    strTypeMsgt.Append( "</tr><tr>");
                            }
                            strTypeMsgt.Append("</tr></table>");
                        }
                    }
                }
            }
        }



    }
}